package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.DaFuWengActivity;
import com.yanqu.road.server.manager.cross.battle.DaFuWengMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.C_CROSS_DA_FU_WENG_BOSS_SHARE_NEWS, desc = "跨服分享情报")
public class CrossShareNewsCmd extends CrossUnionCommand {
    private String unionUid;
    private int bossId;
    private int activityId;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.ShareNewsToCrossReqMsg msg = MonopolyProto.ShareNewsToCrossReqMsg.parseFrom(packet.getBytes());
        unionUid = msg.getUnionUid();
        activityId = msg.getActivityId();
        bossId = msg.getBossId();
        userId = packet.getPlayerId();
        activityId = msg.getActivityId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DaFuWengActivity daFuWengActivity = DaFuWengMgr.getDaFuWengActivity(activityId, groupId);
        int addNewsResult = 0;
        if (!StringUtils.isNullOrEmpty(unionUid)) {
            addNewsResult = daFuWengActivity.addUnionNews(serverId, userId, unionUid, bossId);
        }
        MonopolyProto.GiveUpBossShareNewsRespMsg.Builder respMsg = MonopolyProto.GiveUpBossShareNewsRespMsg.newBuilder();
        respMsg.setRet(0);
        //分享结果不提示 参数都修改为0 暂不剔除
        respMsg.setAddNewsResult(0);
        respMsg.setRet(0);
        YanQuMessage yanQuMessage = YanQuMessageUtils.buildMessage(ClientProtocol.U_DA_FU_WENG_GIVE_UP_BOSS_SHARE_NEWS, respMsg);
        MessageHelper.sendPacket(serverId, userId, yanQuMessage);
    }

    @Override
    public void sendData() {

    }
}
